package test.temple;

import java.util.List;
import com.weight.common.generate.base.ResourceFile;

/**
* 
*  
*/
public class MapperXmlResourceFile extends ResourceFile {
	private static final String FILE_NAME = "Mapper.xml";
	public MapperXmlResourceFile(String filePath,String model,String packPath,List<String> fieldDOList,
			List<String> fieldENList,List<String> fieldTypeList,String tableName,String tableCnName) {
		super(filePath,getModelClass( model).append(FILE_NAME).toString());
		String projectName=getModelClass(model).toString();
		String cnName=tableCnName.substring(0, tableCnName.length()-1);
		StringBuilder  resourceFile =new StringBuilder();
		
		
		
		resourceFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
		resourceFile.append("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" "
				+ "\"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n");
		resourceFile.append("<mapper namespace=\"").append(packPath).append(".DAO.")
		.append(projectName).append("Mapper\">\n");
		resourceFile.append("\n");
		resourceFile.append("\t<resultMap id=\"BaseResultMap").append(projectName).append("\" type=\"")
		.append(packPath).append(".PO.").append(projectName).append("\">\n");
		
		for(int i=0;i<fieldDOList.size();i++) {
			if(i==0) {
				if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
					resourceFile.append("\t\t<id column=\"").append(fieldDOList.get(i)).append("\" jdbcType=\"")
					.append(fieldTypeList.get(i).toUpperCase()).append("\" property=\"").append(fieldENList.get(i)).append("\" />\n");
				}else {
					
					resourceFile.append("\t\t<id column=\"").append(tableName).append("_id\" jdbcType=\"INTEGER\" property=\"")
					.append(model).append("Id\" />\n");
					
					resourceFile.append("\t\t<result column=\"").append(fieldDOList.get(i)).append("\" jdbcType=\"")
					.append(fieldTypeList.get(i).toUpperCase()).append("\" property=\"").append(fieldENList.get(i)).append("\" />\n");
				}
			}else{
				resourceFile.append("\t\t<result column=\"").append(fieldDOList.get(i)).append("\" jdbcType=\"")
				.append(fieldTypeList.get(i).toUpperCase()).append("\" property=\"").append(fieldENList.get(i)).append("\" />\n");
			}
		}
		
		
		if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
			resourceFile.append("\t\t<result column=\"create_time\" jdbcType=\"TIMESTAMP\" property=\"createTime\" />\n");
			resourceFile.append("\t\t<result column=\"update_time\" jdbcType=\"TIMESTAMP\" property=\"updateTime\" />\n");
			resourceFile.append("\t\t<result column=\"create_by\" jdbcType=\"VARCHAR\" property=\"createBy\" />\n");
			resourceFile.append("\t\t<result column=\"update_by\" jdbcType=\"VARCHAR\" property=\"updateBy\" />\n");
			resourceFile.append("\t\t<result column=\"standbyfield1\" jdbcType=\"VARCHAR\" property=\"standbyfield1\" />\n");
			resourceFile.append("\t\t<result column=\"standbyfield2\" jdbcType=\"VARCHAR\" property=\"standbyfield2\" />\n");
			resourceFile.append("\t\t<result column=\"standbyfield3\" jdbcType=\"VARCHAR\" property=\"standbyfield3\" />\n");
		}
		resourceFile.append("\t</resultMap>\n");
		resourceFile.append("\n");
		resourceFile.append("\t<sql id=\"Base_Column_List_").append(projectName).append("\" >\n");
		resourceFile.append("\t\t\t");
		
		for(int i=0;i<fieldDOList.size();i++) {
			if(i!=fieldDOList.size()-1) {
				if(i==0&&!tableName.endsWith("_info")||tableName.endsWith("_log")) {
					resourceFile.append(tableName).append("_id,");
				}
				resourceFile.append(fieldDOList.get(i)).append(",");
			}else {
				resourceFile.append(fieldDOList.get(i));
			}
		}
		resourceFile.append("\n");
		
		if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
			resourceFile.append(",create_time,update_time,create_by,update_by,standbyfield1,standbyfield2,standbyfield3");
		}
		resourceFile.append("\t</sql>\n");
		resourceFile.append("\n");
		
		
		
		if(tableName.endsWith("_info")||tableName.endsWith("_log")||tableName.endsWith("_norm")) {
	//查询
			resourceFile.append("\t<!--查询").append(cnName).append("-->\n");
			resourceFile.append("\t<select id=\"find").append(projectName).append("ByT\" parameterType=\"")
			.append(projectName).append("\" resultMap=\"BaseResultMap").append(projectName).append("\">\n");
			resourceFile.append("\t\tselect  \n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName).append("\twhere\n");
			for(int i=0;i<fieldDOList.size();i++) {
				resourceFile.append("\t\t\t<if test=\"").append(fieldENList.get(i)).append("!=null and ")
				.append(fieldENList.get(i)).append("!=''\">").append(fieldDOList.get(i)).append("=#{")
				.append(fieldENList.get(i)).append(",jdbcType=")
				.append(fieldTypeList.get(i).toUpperCase()).append("} and </if> \n");
			}
			
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\t<if test=\"createTime!=null and createTime!='' \">create_time=#{createTime,jdbcType=TIMESTAMP} and </if>\n");
				resourceFile.append("\t\t\t<if test=\"updateTime!=null and updateTime!='' \">update_time=#{updateTime,jdbcType=TIMESTAMP} and </if>\n");
				resourceFile.append("\t\t\t<if test=\"createBy!=null and createBy!='' \">create_by=#{createBy,jdbcType=VARCHAR} and </if>\n");
				resourceFile.append("\t\t\t<if test=\"updateBy!=null and updateBy!='' \">update_by=#{updateBy,jdbcType=VARCHAR} and </if>\n ");
				resourceFile.append("\t\t\t<if test=\"standbyfield1!=null and standbyfield1!='' \">standbyfield1=#{standbyfield1,jdbcType=VARCHAR} and </if>\n ");
				resourceFile.append("\t\t\t<if test=\"standbyfield2!=null and standbyfield2!='' \">standbyfield2=#{standbyfield2,jdbcType=VARCHAR} and </if>\n ");
				resourceFile.append("\t\t\t<if test=\"standbyfield3!=null and standbyfield3!='' \">standbyfield3=#{standbyfield3,jdbcType=VARCHAR} and </if>\n");
			}
			resourceFile.append("\t\t\tis_del='1' \n");
			
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\torder by update_time desc \n");
			}
			
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
	//查询所有菜单信息
			resourceFile.append("\t<!--查询所有").append(cnName).append("信息-->\n");
			resourceFile.append("\t<select id=\"findAll\" parameterType=\"Map\" resultMap=\"BaseResultMap").append(projectName).append("\">\n");
			resourceFile.append("\t\tselect\n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName);
			resourceFile.append("\twhere\tis_del='1'\t").append("\n");
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\torder by update_time desc \n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
	//查询菜单信息总数
			resourceFile.append("\t<!--查询").append(cnName).append("总数-->\n");
			resourceFile.append("\t<select id=\"find").append(projectName).append("Count\" resultType=\"Integer\">\n");
			resourceFile.append("\t\tselect count(");
			if(fieldDOList.size()>0) {
				resourceFile.append(fieldENList.get(0));
			}
			resourceFile.append( ")\tfrom\t").append(tableName).append("\twhere\tis_del='1'\t").append("\n");
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");		
	
	//ID查询
			resourceFile.append("\t<!--ID查询").append(cnName).append("信息 -->\n");
			resourceFile.append("\t<select id=\"findBy").append(projectName)
			.append("Id\" parameterType=\"Map\" resultMap=\"BaseResultMap").append(projectName).append("\">\n");
			resourceFile.append("\t\tselect\n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\tis_del='1'\tand\t").append(fieldDOList.get(0)).append("=#{")
				.append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
	//ID查询 批量
			resourceFile.append("\t<!--ID查询").append(cnName).append("信息 批量-->\n");
			resourceFile.append("\t<select id=\"findBy").append(projectName)
			.append("IdList\" parameterType=\"List\" resultType=\"String\">\n");
			resourceFile.append("\t\tselect\n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\tis_del='1'\tand\t").append(fieldDOList.get(0)).append("\tin\n")
				.append("\t\t<foreach collection=\"list\" item=\"").append(fieldENList.get(0))
				.append("\" open=\"(\" separator=\",\" close=\")\">\n\t\t\t")
				.append(fieldDOList.get(0)).append("=#{")
				.append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n")
				.append("\t\t</foreach>\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");		
	  
			
			
	//插入
			resourceFile.append("\t<!--插入").append(cnName).append("-->\n");
			resourceFile.append("\t<insert\tid=\"insert").append(projectName).append("\" parameterType=\"")
			.append(projectName).append("\" >\n");
			resourceFile.append("\t\tinsert\tinto\t").append(tableName).append("\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(").append(fieldDOList.get(i)).append(",");
				}else if(i==fieldDOList.size()-1) {
					resourceFile.append(fieldDOList.get(i));
				}else{
					resourceFile.append(fieldDOList.get(i)).append(",");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append(",create_by,update_by,standbyfield1,standbyfield2,standbyfield3");
			}
			resourceFile.append(")\n");
			resourceFile.append("\t\tvalues\t\n");
			for(int i=0;i<fieldENList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(#{").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}else if(fieldDOList.get(i).equals("is_del")) {
					resourceFile.append("'1',");
				}else if(i==fieldENList.size()-1) {
					resourceFile.append("#{").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("}");
				}else{
					resourceFile.append("#{").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}
				if(i>0&&i%9==0) {
					resourceFile.append("\n\t\t\t");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append(",#{createBy,jdbcType=VARCHAR},#{updateBy,jdbcType=VARCHAR},#{standbyfield1,jdbcType=VARCHAR}"
						+ ",#{standbyfield2,jdbcType=VARCHAR},#{standbyfield3,jdbcType=VARCHAR}");
			}
			resourceFile.append(")\n");
			resourceFile.append("\t</insert>\n");
			resourceFile.append("\n");
	//批量添加		
			resourceFile.append("\t<!--批量添加").append(cnName).append("-->\n");
			resourceFile.append("\t<insert\tid=\"insert").append(projectName).append("Batch\" parameterType=\"List\" >\n");
			resourceFile.append("\t\tinsert\tinto\t").append(tableName).append("\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(").append(fieldDOList.get(i)).append(",");
				}else if(i==fieldDOList.size()-1) {
					resourceFile.append(fieldDOList.get(i));
				}else{
					resourceFile.append(fieldDOList.get(i)).append(",");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append(",create_by,update_by,standbyfield1,standbyfield2,standbyfield3");
			}
			resourceFile.append(")\n");
			resourceFile.append("\t\tvalues\t\n");
			resourceFile.append("\t\t<foreach collection=\"list\" item=\"params\" index=\"index\"  separator=\",\">\n");
			for(int i=0;i<fieldENList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}else if(i==fieldENList.size()-1) {
					resourceFile.append("#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("}");
				}else{
					resourceFile.append("#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}
				if(i>0&&i%9==0) {
					resourceFile.append("\n\t\t\t");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append(",#{params.createBy,jdbcType=VARCHAR},#{params.updateBy,jdbcType=VARCHAR},"
				+ "#{params.standbyfield1,jdbcType=VARCHAR},#{params.standbyfield2,jdbcType=VARCHAR},#{params.standbyfield3,jdbcType=VARCHAR}");
			}
			resourceFile.append(")\n");
			resourceFile.append("\t\t</foreach>\n");
			resourceFile.append("\t</insert>\n");
			resourceFile.append("\n");
	//修改
			resourceFile.append("\t<!--修改").append(cnName).append("-->\n");
			resourceFile.append("\t<update id=\"update").append(projectName).append("\" parameterType=\"")
			.append(projectName).append("\" >\n");
			resourceFile.append("\t\tupdate\t").append(tableName).append("\tset\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i>0) {//&&!"is_del,create_time,create_by,update_time".contains(fieldDOList.get(i)
					resourceFile.append("\t\t\t<if test=\"").append(fieldENList.get(i)).append("!=null\">")
					.append(fieldDOList.get(i)).append("=#{").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},</if> \n");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\t<if test=\"updateTime!=null\">update_time=#{updateTime,jdbcType=TIMESTAMP},</if>\n");
				resourceFile.append("\t\t\t<if test=\"updateBy!=null\">update_by=#{updateBy,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield1!=null\">standbyfield1=#{standbyfield1,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield2!=null\">standbyfield2=#{standbyfield2,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield3!=null\">standbyfield3=#{standbyfield3,jdbcType=VARCHAR},</if>\n");
			}
			
			if(fieldDOList.size()>0) {
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
				resourceFile.append("\t\twhere\t\n");
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</update>\n");
			resourceFile.append("\n");
			
	//修改
			resourceFile.append("\t<!--修改").append(cnName).append("-->\n");
			resourceFile.append("\t<update id=\"update").append(projectName).append("Limt\" parameterType=\"")
			.append(projectName).append("\" >\n");
			resourceFile.append("\t\tupdate\t").append(tableName).append("\tset\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i>0) {//&&!"is_del,create_time,create_by,update_time".contains(fieldDOList.get(i)
					resourceFile.append("\t\t\t<if test=\"").append(fieldENList.get(i)).append("!=null and ")
					.append(fieldENList.get(i)).append("!=''\">").append(fieldDOList.get(i))
					.append("=#{").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},</if> \n");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\t<if test=\"updateTime!=null\">update_time=#{updateTime,jdbcType=TIMESTAMP},</if>\n");
				resourceFile.append("\t\t\t<if test=\"updateBy!=null\">update_by=#{updateBy,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield1!=null\">standbyfield1=#{standbyfield1,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield2!=null\">standbyfield2=#{standbyfield2,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"standbyfield3!=null\">standbyfield3=#{standbyfield3,jdbcType=VARCHAR},</if>\n");
			}
			
			if(fieldDOList.size()>0) {
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
				resourceFile.append("\t\twhere\t\n");
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</update>\n");
			resourceFile.append("\n");
			
	//批量修改
			resourceFile.append("\t<!--批量修改").append(cnName).append("-->\n");
			resourceFile.append("\t<update id=\"update").append(projectName).append("Batch\" parameterType=\"List\" >\n");
			resourceFile.append("\t\t<foreach collection=\"list\" item=\"params\" open=\"(\" separator=\",\" close=\")\">\n");
			resourceFile.append("\t\tupdate\t").append(tableName).append("\tset\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i>0) {//&&!"is_del,create_time,create_by,update_time".contains(fieldDOList.get(i))
					resourceFile.append("\t\t\t<if test=\"params.").append(fieldENList.get(i)).append("!=null\">")
					.append(fieldDOList.get(i)).append("=#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},</if> \n");
				}
			}
			if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
				resourceFile.append("\t\t\t<if test=\"params.updateTime!=null\">update_time=#{params.updateTime,jdbcType=TIMESTAMP},</if>\n");
				resourceFile.append("\t\t\t<if test=\"params.updateBy!=null\">update_by=#{params.updateBy,jdbcType=VARCHAR},</if>\n ");
				resourceFile.append("\t\t\t<if test=\"params.standbyfield1!=null\">standbyfield1=#{params.standbyfield1,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"params.standbyfield2!=null\">standbyfield2=#{params.standbyfield2,jdbcType=VARCHAR},</if>\n");
				resourceFile.append("\t\t\t<if test=\"params.standbyfield3!=null\">standbyfield3=#{params.standbyfield3,jdbcType=VARCHAR},</if>\n");
			}
			if(fieldDOList.size()>0) {
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{params.")
				.append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
				resourceFile.append("\t\twhere\t\n");
				resourceFile.append("\t\t\t").append(fieldDOList.get(0)).append("=#{params.")
				.append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t\t</foreach>\n");
			resourceFile.append("\t</update>\n");
			resourceFile.append("\n");
	//物理删除
			resourceFile.append("\t<!--物理删除").append(cnName).append("-->\n");
			resourceFile.append("\t<delete id=\"deleteBy").append(projectName).append("Id\" parameterType=\"Map\" >\n");
			resourceFile.append("\t\tdelete\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</delete>\n");
			resourceFile.append("\n");
	//批量物理删除
			resourceFile.append("\t<!--批量物理删除").append(cnName).append("-->\n");
			resourceFile.append("\t<delete id=\"deleteBy").append(projectName).append("IdBatch\" parameterType=\"List\" >\n");
			resourceFile.append("\t\tdelete\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("\tin\t\n");
			}
			resourceFile.append("\t\t<foreach collection=\"list\" item=\"").append(fieldENList.get(0))
			.append("\" open=\"(\" separator=\",\" close=\")\">\n");
			resourceFile.append("\t\t\t#{").append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase())
			.append("}\n");
			resourceFile.append("\t\t</foreach>\n");
			resourceFile.append("\t</delete>\n");
			resourceFile.append("\n");
		}
		
		if(tableName.endsWith("_info")||tableName.endsWith("_log")) {
	//状态删除
			resourceFile.append("\t<!--状态删除").append(cnName).append("-->\n");
			resourceFile.append("\t<update id=\"upDelBy").append(projectName).append("Id\" parameterType=\"")
			.append(projectName).append("\" >\n");
			resourceFile.append("\t\tupdate\t").append(tableName).append("\tset\tis_del='0',update_by=#{updateBy,jdbcType=")
			.append(fieldTypeList.get(0).toUpperCase()).append("}\t");
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
				.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</update>\n");
			resourceFile.append("\n");
	//批量状态删除
			resourceFile.append("\t<!--批量状态删除").append(cnName).append("-->\n");
			resourceFile.append("\t<update id=\"upDelBy").append(projectName).append("IdBatch\" parameterType=\"List\" >\n");
			resourceFile.append("\t\tupdate\t").append(tableName).append("\tset\tis_del='0',update_by=#{updateBy,jdbcType=")
			.append(fieldTypeList.get(0).toUpperCase()).append("}\t");
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("\tin\t\n");
			}
			resourceFile.append("\t\t<foreach collection=\"list\" item=\"").append(fieldENList.get(0))
			.append("\" open=\"(\" separator=\",\" close=\")\">\n");
			resourceFile.append("\t\t\t#{").append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase())
			.append("}\n");
			resourceFile.append("\t\t</foreach>\n");
			resourceFile.append("\t</update>\n");
			resourceFile.append("\n");
			
		}
		
		if(tableName.endsWith("_ral")) {
			String ralId=getModelClass(fieldENList.get(0)).toString();
			String ralId2=getModelClass(fieldENList.get(1)).toString();
			
		//ID查询ObjByralId
			resourceFile.append("\t<!--ID查询").append(cnName).append("信息 -->\n");
			resourceFile.append("\t<select id=\"findBy").append(ralId).append("\" parameterType=\"Map\" resultMap=\"BaseResultMap")
						.append(projectName).append("\">\n");
			resourceFile.append("\t\tselect\n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("=#{")
							.append(fieldENList.get(0)).append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
		//ID查询ObjByralId2
			resourceFile.append("\t<!--ID查询").append(cnName).append("信息 -->\n");
			resourceFile.append("\t<select id=\"findBy").append(ralId2).append("\" parameterType=\"Map\" resultMap=\"BaseResultMap")
						.append(projectName).append("\">\n");
			resourceFile.append("\t\tselect\n");
			resourceFile.append("\t\t\t<include refid=\"Base_Column_List_").append(projectName).append("\" />\n");
			resourceFile.append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(1)).append("=#{")
							.append(fieldENList.get(1)).append(",jdbcType=").append(fieldTypeList.get(1).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
		//ID查询ralId2
			resourceFile.append("\t<!--ID查询").append(ralId2).append("信息 -->\n");
			resourceFile.append("\t<select id=\"find").append(ralId2).append("By").append(ralId)
						.append("\" parameterType=\"Map\" resultType=\"String\">\n");
			resourceFile.append("\t\tselect\t").append(fieldDOList.get(1)).append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
							.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
		//ID查询ralId
			resourceFile.append("\t<!--ID查询").append(fieldENList.get(0)).append("信息 -->\n");
			resourceFile.append("\t<select id=\"find").append(ralId).append("By").append(ralId2)
						.append("\" parameterType=\"Map\" resultType=\"String\">\n");
			resourceFile.append("\t\tselect\t").append(fieldDOList.get(0)).append("\t\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(1)).append("=#{").append(fieldENList.get(0))
							.append(",jdbcType=").append(fieldTypeList.get(1).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</select>\n");
			resourceFile.append("\n");
			
		//批量添加		
			resourceFile.append("\t<!--批量添加").append(cnName).append("-->\n");
			resourceFile.append("\t<insert\tid=\"insert").append(projectName).append("Batch\" parameterType=\"List\" >\n");
			resourceFile.append("\t\tinsert\tinto\t").append(tableName).append("\n");
			for(int i=0;i<fieldDOList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(").append(fieldDOList.get(i)).append(",");
				}else if(i==fieldDOList.size()-1) {
					resourceFile.append(fieldDOList.get(i));
				}else{
					resourceFile.append(fieldDOList.get(i)).append(",");
				}
			} 
			resourceFile.append(")\n");
			resourceFile.append("\t\tvalues\t\n");
			resourceFile.append("\t\t<foreach collection=\"list\" item=\"params\" index=\"index\"  separator=\",\">\n");
			for(int i=0;i<fieldENList.size();i++) {
				if(i==0) {
					resourceFile.append("\t\t\t(#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}else if(i==fieldENList.size()-1) {
					resourceFile.append("#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("}");
				}else{
					resourceFile.append("#{params.").append(fieldENList.get(i)).append(",jdbcType=")
					.append(fieldTypeList.get(i).toUpperCase()).append("},");
				}
				if(i>0&&i%9==0) {
					resourceFile.append("\n\t\t\t");
				}
			}
			resourceFile.append(")\n");
			resourceFile.append("\t\t</foreach>\n");
			resourceFile.append("\t</insert>\n");
			resourceFile.append("\n");
			
		//物理删除
			resourceFile.append("\t<!--物理删除").append(cnName).append("By").append(ralId).append("-->\n");
			resourceFile.append("\t<delete id=\"deleteBy").append(ralId).append("\" parameterType=\"Map\" >\n");
			resourceFile.append("\t\tdelete\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(0)).append("=#{").append(fieldENList.get(0))
							.append(",jdbcType=").append(fieldTypeList.get(0).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</delete>\n");
			resourceFile.append("\n");
			
		//物理删除ByralId2
			resourceFile.append("\t<!--物理删除").append(cnName).append("By").append(ralId2).append("-->\n");
			resourceFile.append("\t<delete id=\"deleteBy").append(ralId2).append("\" parameterType=\"Map\" >\n");
			resourceFile.append("\t\tdelete\tfrom\t").append(tableName);
			if(fieldDOList.size()>0) {
				resourceFile.append("\twhere\t").append(fieldDOList.get(1)).append("=#{").append(fieldENList.get(1))
							.append(",jdbcType=").append(fieldTypeList.get(1).toUpperCase()).append("}\n");
			}
			resourceFile.append("\t</delete>\n");
			resourceFile.append("\n");
		}
		
		
		resourceFile.append("</mapper>\n");
		String resource = resourceFile.toString();
		init(resource);
	}
}
